//
//  NewFeatureCell.m
//  OCKSFWeibo
//
//  Created by 盛 发 况 on 16/4/20.
//  Copyright © 2016年 盛 发 况. All rights reserved.
//

#import "NewFeatureCell.h"
#import "CZTabBarController.h"

@interface NewFeatureCell ()
@property (nonatomic, weak) UIImageView *imageView;
@property (nonatomic, weak) UIButton *shareButton;
@property (nonatomic, weak) UIButton *startButton;

@end

@implementation NewFeatureCell
#pragma mark --- 懒加载控件
- (UIImageView *)imageView {
    if (_imageView == nil) {
        
        UIImageView *imageView = [[UIImageView alloc] init];
        _imageView = imageView;
        
        [self.contentView addSubview:_imageView];
    }
    return _imageView;
}
- (UIButton *)shareButton {
    if (_shareButton == nil) {
        
        UIButton *shareButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [shareButton setTitle:@"分享给大家" forState:UIControlStateNormal];
        [shareButton setImage:[UIImage imageNamed:@"new_feature_share_false"] forState:UIControlStateNormal];
        [shareButton setImage:[UIImage imageNamed:@"new_feature_share_true"] forState:UIControlStateSelected];
        [shareButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [shareButton sizeToFit];
        [shareButton addTarget:self action:@selector(shareButtonDidClick:) forControlEvents:UIControlEventTouchUpInside];
        
        _shareButton = shareButton;
        [self.contentView addSubview:_shareButton];
    }
    return _shareButton;
}
- (void)shareButtonDidClick:(UIButton *)button {

    button.selected = !button.isSelected;
}
- (UIButton *)startButton {
    if (_startButton == nil) {
        UIButton *startButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [startButton setBackgroundImage:[UIImage imageNamed:@"new_feature_finish_button"] forState:UIControlStateNormal];
        [startButton setBackgroundImage:[UIImage imageNamed:@"new_feature_finish_button_highlighted"] forState:UIControlStateHighlighted];
        [startButton setTitle:@"开始微博" forState:UIControlStateNormal];
        [startButton sizeToFit];
        [startButton addTarget:self action:@selector(startButtonDidClick) forControlEvents:UIControlEventTouchUpInside];
        
        _startButton = startButton;
        [self.contentView addSubview:startButton];
    }
    return _startButton;
}
- (void)startButtonDidClick {

    CZTabBarController *tabBarVC = [[CZTabBarController alloc] init];
    
    CZKeyWindow.rootViewController = tabBarVC;
}

//赋值
- (void)setImage:(UIImage *)image {
    _image = image;

    self.imageView.image = image;
}
//重新布局子控件
- (void)layoutSubviews {
    [super layoutSubviews];

    //imageView
    self.imageView.frame = self.bounds;
    
    //shareButton
    self.shareButton.center = CGPointMake(self.bounds.size.width * 0.5, self.bounds.size.height * 0.8);
    
    //startButton
    self.startButton.center = CGPointMake(self.width * 0.5, self.height * 0.88);
}

// 判断是否是最后一页
- (void)selectIndexPath:(NSIndexPath *)indexPath count:(int)count {
    if (indexPath.item == count - 1) {
        self.shareButton.hidden = NO;
        self.startButton.hidden = NO;
    } else {
        self.shareButton.hidden = YES;
        self.startButton.hidden = YES;
    }
}


@end





